package com.mark.anto.bootstrap;

import com.mark.anto.annotation.EnableHelloWorldByCode;
import com.mark.anto.annotation.HelloWorldImportSelector;
import com.mark.anto.configuration.HelloWorldConfiguration;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.util.Assert;

/**
 * @Description: 编程方式实现Enable
 * @Author: Mark
 * @CreateDate: 2019/9/1 8:51
 * @Version: 3.00.001
 * @Copyright : 豆浆油条个人非正式工作室
 *
 * 编程方式注入Bean的过程：{@link HelloWorldImportSelector} -> {@link HelloWorldConfiguration} ->{@code helloWorld()}
 */
@EnableHelloWorldByCode
public class EnableHelloWorldByCodeBootstrap {
    public static void main(String[] args) {
        ConfigurableApplicationContext context = new SpringApplicationBuilder(EnableHelloWorldByCodeBootstrap.class)
                .web(WebApplicationType.NONE)
                .run(args);

        //从上下文中获取Bean
        String bean = context.getBean("helloWorld", String.class);
        Assert.notNull(bean, "获取到Bean为为空！");

        //关闭上下文
        context.close();
    }
}
